package org.farm2.tools.db.commons;

import java.util.List;

public class DBSort {
    private String field;
    private SORT_TYPE sort_type;

    public static String getSql(List<DBSort> sorts) {
        StringBuffer sql = new StringBuffer();
        if (sorts.size() > 0) {
            sql.append(" ORDER BY");
        }
        for (int n = 0; n < sorts.size(); n++) {
            if (n == 0) {
                sql.append(" " + sorts.get(n).getField());
            } else {
                sql.append("," + sorts.get(n).getField());
            }
            if (n == sorts.size() - 1) {
                sql.append(" " + sorts.get(n).getSort_type().name());
            }
        }
        return sql.toString();
    }

    public enum SORT_TYPE {ASC, DESC}

    public DBSort(String field, SORT_TYPE sort_type) {
        this.field = field;
        this.sort_type = sort_type;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public SORT_TYPE getSort_type() {
        return sort_type;
    }

    public void setSort_type(SORT_TYPE sort_type) {
        this.sort_type = sort_type;
    }
}
